import re


class JJX():
    def __init__(self, sel, inse):
        self.sel = sel
        self.inse = inse

    # 分线|分纤|交接箱|光站|放大器|分支|分配|缆桥|光机|小光机|电源箱

    def select(self):
        if self.sel in ("分线", "分纤"):
            return 14
        elif self.sel in ("交接箱"):
            if self.selectWall() in ("壁挂", "挂壁"):
                return 15
            elif self.selectWall() in ("落地"):
                if self.selectBase() in ("不含"):
                    return 17
                elif self.selectBase() in ("底座", "底基", "基座", "基础"):
                    return 16
        elif self.sel in ("光站"):
            if self.selectBox() in ("箱"):
                if self.selectBase() in ("不含"):
                    return 19
                elif self.selectBase() in ("底座", "底基", "基座", "基础"):
                    return 18
            elif self.selectBox() in ("器"):
                return 28
        elif self.sel in ("放大器"):
            if self.selectBox() in ("箱"):
                if self.selectBase() in ("不含"):
                    return 21
                elif self.selectBase() in ("底座", "底基", "基座", "基础"):
                    return 20
            elif self.selectBox() in ("器"):
                return 30

        elif self.sel in ("分支", "分配"):
            if self.selectWall() in ("壁挂", "挂壁"):
                return 25
            elif self.selectWall() in ("落地"):
                if self.selectBase() in ("底座", "底基", "基座", "基础"):
                    return 22
                elif self.selectBase() in ("不含"):
                    return 23
        elif self.sel in ("缆桥"):
            if self.selectBox() in ("箱"):
                return 24
            elif self.selectBox() in ("器"):
                return 26
        elif self.sel in ("光机"):
            if self.selectSmall() in ("小光机"):
                return 29
            elif self.selectSmall() in ("光机"):
                return 27
        elif self.sel in ("电源箱"):
            return 31

    """该方法判断是否为小光机字"""

    def selectSmall(self):
        try:
            sel = re.findall("小光机", self.inse)[0]
            return sel
        except:
            return "光机"

    """该方法判断是否为箱字"""

    def selectBox(self):
        try:
            sel = re.findall("箱", self.inse)[0]
            return sel
        except:
            return "器"

    """该方法判断是否挂壁或者落地"""

    def selectWall(self):
        try:
            sel = re.findall("落地|挂壁|壁挂", self.inse)[0]
            return sel
        except:
            return "落地"

    """该方法判断交接箱是否含地基"""

    def selectBase(self):
        try:
            sel = re.findall("|不含|底座|底基|基座|基础", self.inse)[0]
            return sel
        except:
            print("交接箱未标注挂壁还是落地默认含基础")
            return "底座"

    def getJJX(self):
        return self.select()
